Learning Flex Basics (Part 3) : Working with Containers
Complete Code Listing for containers.mxml
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" >
<mx:Script>
<![CDATA[
// data array
var myArray=[0,1,2,3,4,5,6,7,8,9];
// handler for tile
function setStatus(item:Number):Void
{
tilePanel.status="Item: "+item;
}
function scaleUp():Void
{
for (var i:Number=0;i<vBar.length;i++)
{
vBar[i].height=vBar[i].height*2;
}
}
function scaleDown():Void
{
for (var i:Number=0;i<vBar.length;i++)
{
vBar[i].height=vBar[i].height/2;
}
}
]]>
</mx:Script>
<!-- global navigation -->
<mx:TabNavigator id="tabNav" marginLeft="10" marginTop="20" height="500" width="500">
<!-- view 1 -->
<mx:HBox label="View 1: Form/Tile">
<!-- section navigation -->
<mx:LinkBar dataProvider="{vStack}" direction="vertical"/>
<mx:ViewStack id="vStack">
<!-- form view -->
<mx:Panel title="Form" label="Form">
<mx:Form>
<mx:FormHeading label="My Form"/>
<mx:FormItem label="Pick a Number">
<mx:ComboBox id="myCombo" dataProvider="{myArray}"/>
</mx:FormItem>
</mx:Form>
<mx:ControlBar>
<mx:Label text="You chose: {myCombo.selectedItem}"/>
</mx:ControlBar>
</mx:Panel>
<!-- tile view -->
<mx:Panel id="tilePanel" title="Tile" label="Tile">
<mx:Tile width="400">
<mx:Repeater id="myRep" dataProvider="{myArray}">
<mx:VBox borderStyle="solid" mouseDown="setStatus(event.target.getRepeaterItem())">
<mx:Label text="index: {myRep.currentIndex} - item: {myRep.currentItem}"/>
</mx:VBox>
</mx:Repeater>
</mx:Tile>
</mx:Panel>
</mx:ViewStack>
</mx:HBox>
<!-- view 2 -->
<mx:Panel id="barPanel" label="View 2: Pseudo Bar Chart" title="Pseudo Bar Chart" height="{.9*tabNav.height}">
<mx:HBox height="{.8*barPanel.height}" verticalAlign="bottom">
<mx:Repeater id="barRep" dataProvider="{myArray}">
<mx:VBox id="vBar" backgroundColor="0x99CCCC" height="{20*barRep.currentItem}" width="40" horizontalAlign="center">
<mx:Label text="{barRep.currentItem}"/>
</mx:VBox>
</mx:Repeater>
</mx:HBox>
<mx:ControlBar>
<mx:Button label="Scale Up" click="scaleUp()"/>
<mx:Button label="Scale Down" click="scaleDown()"/>
</mx:ControlBar>
</mx:Panel>
</mx:TabNavigator>
</mx:Application>